package com.powernode.web.controller;

import com.powernode.web.model.dto.LoginTokenDto;
import com.powernode.web.result.CommonResult;
import com.powernode.web.model.query.LoginQuery;
import com.powernode.web.service.OperatorService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/operator") // url统一前缀
public class OperatorController {

    @Resource
    private OperatorService operatorService;

    /**
     * @RequestBody 标注形参来自于请求体，一般是json格式
     * @Validated 标注的形参要进行BeanValidation验证，验证方式在数据类中编写
     */
    @PostMapping("/access")
    public CommonResult accessToken(@RequestBody @Validated LoginQuery loginQuery){
        // 查询用户名密码是否正确，生成jwt返回前端
        LoginTokenDto loginTokenDto = operatorService.accessToken(loginQuery);
        return CommonResult.ok(loginTokenDto);
    }
}
